package is.progetto2.activity;

import java.util.Stack;

import is.progetto2.activity.abstraction.AbstractJobFactory;

public class JobFactoryImp extends AbstractJobFactory {
	private static int ID_JOB=0;
	/*
	 * Usato per mantere l'id dei bind eliminati per poi ricrearli
	 */
	private Stack<Integer> stackID;

	@Override
	public Job createJob(int duration) {
		if(stackID.isEmpty()){
			return new Job(++ID_JOB,duration);
		}
		return new Job(stackID.pop(),duration);
	}
	
	private JobFactoryImp(){
		this.stackID=new Stack<>();
	}
	
	protected static JobFactoryImp getDefaultInstance(){
		return new JobFactoryImp();
	}

	@Override
	public void remove(Job j) {
		stackID.push(j.getId());
	}

}
